<template>
  <div id="cornerComment" v-if="dialogVisible">
    <div class="cornerComment-in">
      <div class="cornerComment-in-title">
        <span>游园活动子项目详情</span>
        <span class="el-icon-circle-close close-Btn-line" @click="closePOpup"></span>
      </div>
      <div class="commentBody apply-box-left-from">
        <el-form label-width="100px" ref="editForm">
          <el-form-item label="项目名称：">
            <el-input v-model="infoForm.title" placeholder="项目名称" size="small"></el-input>
          </el-form-item>
          <el-form-item label="负责人：">
            <el-button size="small" type="primary" plain @click="uservisible=true">选择负责人</el-button>
            {{ userData ? `【${userData.realname}】` : '' }}
          </el-form-item>
          <el-form-item label="项目简介：">
            <el-input
                type="textarea"
                placeholder="项目简介"
                v-model="infoForm.description"
                maxlength="300"
                show-word-limit
                :autosize="{ minRows: 6, maxRows: 8 }"
            ></el-input>
          </el-form-item>
        </el-form>
      </div>
      <div class="cornerComment-in-footer">
        <el-button @click.native="closePOpup" size="small">返回</el-button>
        <el-button @click.native="saveProjectsFn()" size="small" type="primary" plain>确定并保存</el-button>
      </div>
    </div>
    <singleTeacherModle :visible.sync="uservisible" @studentFn="getUser"></singleTeacherModle>
  </div>
</template>

<script>
import {garden_party_option_add, garden_party_option_Detail, garden_party_option_edit} from "@/api/admin/school"

export default {
  props: ['visible', 'detailId', 'parentsId'], // recruitmentType examine 审核
  components: {},
  data() {
    return {
      dialogVisible: false,
      infoForm: {
        title: '',
        description: '',
      },
      userData: null,
      uservisible: false
    }
  },
  watch: {
    visible() {
      this.dialogVisible = this.visible
      if (this.visible) {
        if (this.detailId) {
          this.getDetail()
        }
      } else {
        this.infoForm = {
          title: '',
          description: '',
        }
        this.userData = null
      }
    }
  },
  created() {

  },
  methods: {
    getDetail() {
      garden_party_option_Detail({id: this.detailId}).then(res => {
        console.log('res:', res)
        let data_ = JSON.parse(JSON.stringify(res.vo))
        this.infoForm.title = data_.title
        this.infoForm.description = data_.description
        this.userData = data_.user
      })
    },
    saveProjectsFn() {
      let data_ = JSON.parse(JSON.stringify(this.infoForm))
      if (!data_.title) {
        this.$message.error('填写活动名称')
        return
      }
      if (!data_.description) {
        this.$message.error('填写活动简介')
        return
      }

      data_.garden_party_id = this.parentsId
      data_.user_id = this.userData.id
      if (this.detailId) {
        data_.id = this.detailId
        garden_party_option_edit(data_).then(res => {
          console.log('res:', res)
          this.$message.success(res.msg)
          this.$emit('InitFn')
          this.closePOpup()
        })
      } else {
        garden_party_option_add(data_).then(res => {
          console.log('res:', res)
          this.$message.success(res.msg)
          this.$emit('InitFn')
          this.closePOpup()
        })
      }
    },
    // 关闭弹窗
    closePOpup() {
      this.$emit('update:visible', false)
    },
    getJson(option) {
      return JSON.parse(JSON.stringify(option))
    },
    getUser(option) {
      console.log('option:', option)
      this.userData = JSON.parse(JSON.stringify(option))
    },
  },
  mounted() {
  }
}
</script>
<style scoped>
#cornerComment {
  height: 100vh;
  width: 100%;
  position: fixed;
  top: 0;
  left: 0;
  background: rgba(0, 0, 0, .5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9;
}

.cornerComment-in {
  width: 600px;
  height: auto;
  background: #fff;
  display: flex;
  flex-direction: column;
  border-radius: 5px;
}

.cornerComment-in-title {
  height: 50px;
  display: flex;
  align-items: center;
  border-bottom: 1px solid #ddd;
  font-size: 24px;
}

.cornerComment-in-title span {
  padding: 0 10px;
}

.cornerComment-in-title span:first-child {
  flex: 1;
  font-size: 16px;
}

.cornerComment-in-footer {
  height: 50px;
  border-top: 1px solid #ddd;
  display: flex;
  align-items: center;
  padding: 0 10px;
  justify-content: center;
}

.commentBody {
  padding: 10px;
  flex: 1;
  overflow-y: auto;
}

.close-Btn-line {
  cursor: pointer;
}

</style>


